# Maintainer: Daurnimator <daurnimator@archlinux.org>
# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Tomas Krizek <tomas.krizek@nic.cz>
# Contributor: Ondřej Surý <ondrej@sury.org>

pkgname=knot-resolver
pkgver=5.7.0
pkgrel=2
arch=('loong64' 'x86_64')
pkgdesc="Caching DNSSEC-validating DNS resolver"
url='https://www.knot-resolver.cz/'
license=('GPL3')
depends=(
    'dnssec-anchors'
    'gnutls'
    'knot'
    'libedit'
    'libuv'
    'lmdb'
    'luajit'
    'libcap-ng'
    'libnghttp2'
    'systemd-libs'
)
makedepends=(
    'cmocka'
    'meson'
)
optdepends=(
    'lua51-basexx: experimental_dot_auth module'
    'lua51-cqueues: http and dns64 module, policy.rpz() function'
    # TODO: 'lua51-etcd: etcd module'
    'lua51-http: http and prefill modules, trust_anchors bootstrap'
    'lua51-psl: policy.slice_randomize_psl() function'
)
backup=('etc/knot-resolver/kresd.conf')
source=("https://secure.nic.cz/files/${pkgname}/${pkgname}-${pkgver}.tar.xz"{,.asc})
sha256sums=('383ef6db1cccabd2dd788ea9385f05e98a2bafdfeb7f0eda57ff9d572f4fad71'
            'SKIP')
validpgpkeys=(3057EE9A448F362D74205A779AB120DA0A76F6DE  # Ales Mrazek <ales.mrazek@nic.cz>
              B6006460B60A80E782062449E747DF1F9575A3AA) # Vladimír Čunát (work) <vladimir.cunat@nic.cz>

build() {
    cd ${pkgname}-${pkgver}
    arch-meson build \
        -D keyfile_default=/etc/trusted-key.key \
        -D systemd_files=enabled \
        -D client=enabled \
        -D install_kresd_conf=enabled \
        -D unit_tests=enabled
    ninja -C build
}

check() {
    meson test -C ${pkgname}-${pkgver}/build
}

package() {
    DESTDIR="${pkgdir}" ninja -C ${pkgname}-${pkgver}/build install

    # add kresd.target to multi-user.target.wants to support enabling kresd services
    mkdir -p "${pkgdir}/usr/lib/systemd/system/multi-user.target.wants/"
    ln -s ../kresd.target "${pkgdir}/usr/lib/systemd/system/multi-user.target.wants/kresd.target"
}
